package com.nlx.notes.module.helper.flow;

import com.google.common.eventbus.EventBus;
import com.nlx.notes.module.bean.dto.flow.FlowChangeDTO;
import com.nlx.notes.module.core.util.JSONUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class FlowEventHelper {

    private static final EventBus FLOW_CHANGE_EVENT_BUS = new EventBus();

    public static void regAllFlowHandler(Object flowHandler){
        if(null != flowHandler){
            FLOW_CHANGE_EVENT_BUS.register(flowHandler);
        }
    }

    /**
     * 流水变更
     * @param flowChangeDTO 流水参数
     */
    public void flowChange(FlowChangeDTO flowChangeDTO){
        log.info("流水发生变更了，流水 {}", JSONUtils.toString(flowChangeDTO));
        FLOW_CHANGE_EVENT_BUS.post(flowChangeDTO);
        log.info("流水事件变更完成");
    }
}
